<?php
/**
 * Created by Veyron
 * User: Vy
 * motto:现在的拼搏 为了更好的明天
 * day:  2020/1/17
 * Time: 11:33
 */
declare(strict_types=1);
namespace app\api\controller;
use think\exception\ValidateException;
use app\common\business\Sms as SmsBus;
class Sms extends ApiBase {
    public function code():object {
        $phoneNumber = input('param.phone_number','','trim');
        $data = [
            'phone_number' => $phoneNumber,
        ];
        try {
            validate(\app\api\validate\User::class)->scene('send_code')->check($data);
        }catch (ValidateException $e){
            return show(config('status.error'),$e->getMessage());
        }

        $type = 'ali';
        //aliyun 调试模式不发送短信
        if(config('aliyun.ali_debug')){
            $type = 'test';
        }
        //调用business数据
        if(SmsBus::sendCode($phoneNumber,6,$type)){
            return show(config('status.success'),'发送验证码成功');
        }
        return show(config('status.error'),'发送验证码失败');
    }

}
